package Test;

import java.util.ArrayList;

import org.testng.annotations.*;

import Group.Player;
import rps.RPSEnum;
import rps.Result;
import rps.RockPaperScissors;

public class TestRockPapersScissors {

	
	private RockPaperScissors rps;
	private Player[] p;
	
	@SuppressWarnings("unchecked")
	@BeforeClass
	public void setUpClass()
	{
		p=new Player[8];
		rps= new RockPaperScissors();
		ArrayList<RPSEnum> moves=new ArrayList<RPSEnum>();
		moves.add(RPSEnum.SCISSORS);moves.add(RPSEnum.SCISSORS);moves.add(RPSEnum.SCISSORS);
		moves.add(RPSEnum.ROCK);moves.add(RPSEnum.SCISSORS);moves.add(RPSEnum.SCISSORS);
		moves.add(RPSEnum.SCISSORS);moves.add(RPSEnum.SCISSORS);moves.add(RPSEnum.SCISSORS);
		moves.add(RPSEnum.SCISSORS);
		
		p[0]=new Player("TOTO",(ArrayList<RPSEnum>)moves.clone());
		p[2]=new Player("TOTO2",(ArrayList<RPSEnum>)moves.clone());
		p[3]=new Player("TOTO3",(ArrayList<RPSEnum>)moves.clone());
		p[4]=new Player("TOTO4",(ArrayList<RPSEnum>)moves.clone());
		
		moves.clear();
		moves.add(RPSEnum.PAPER);moves.add(RPSEnum.PAPER);moves.add(RPSEnum.PAPER);
		moves.add(RPSEnum.ROCK);moves.add(RPSEnum.SCISSORS);moves.add(RPSEnum.PAPER);
		moves.add(RPSEnum.SCISSORS);moves.add(RPSEnum.SCISSORS);moves.add(RPSEnum.ROCK);
		moves.add(RPSEnum.SCISSORS);
		
		p[1]=new Player("TATA",(ArrayList<RPSEnum>)moves.clone());
		p[5]=new Player("TATA2",(ArrayList<RPSEnum>)moves.clone());
		
		
		//
		p[6]=new Player("RAND1");
		p[7]=new Player("RAND2");
		
	}
	
	@AfterClass
	public void tearDownClass(){
		rps=null;
		int i;
		for(i=0;i<8;i++)p[i]=null;
	}
	
	@Test
	public void testWinPlay_Player(){	
		Result tmp=rps.play(p[0],p[1]);		
		assert (tmp==Result.WIN);
	}
	@Test
	void testTiePlay_Player(){
		Result tmp=rps.play(p[2],p[3]);
		
		assert (tmp==Result.TIE);
	}
	
	@Test
	void testLostPlay_Player(){
	Result tmp=rps.play(p[5],p[4]);
	
	assert (tmp==Result.LOST);
	}
	
	
	@Test
	void testRand_Player(){
	int i,j=0;
		for(i=0;i<10;i++){
		if(p[6].getNextMove()==p[7].getNextMove())j++;
	}
		assert (j<8);
	}
	
	
	
	
	/////////////////////////////////////////////////
	//			Previous Test					////
	///////////////////////////////////////////////
	
	@DataProvider(name = "testWIN",parallel = true)
	public Object[][] createDataWIN() {
	 return new Object[][] {
	   { RPSEnum.PAPER,RPSEnum.ROCK},
	   { RPSEnum.ROCK,RPSEnum.SCISSORS},
	   {RPSEnum.SCISSORS,RPSEnum.PAPER}
	 };	
	}
	
	@DataProvider(name = "testTIE",parallel = true)
	public Object[][] createDataTIE() {
	 return new Object[][] {
	   { RPSEnum.PAPER,RPSEnum.PAPER},
	   {RPSEnum.ROCK,RPSEnum.ROCK},
	   { RPSEnum.SCISSORS,RPSEnum.SCISSORS},
	 };
	}
	
	@DataProvider(name = "testLOST",parallel = true)
	public Object[][] createDataLOST() {
	 return new Object[][] {
			 { RPSEnum.ROCK,RPSEnum.PAPER},
			   { RPSEnum.SCISSORS,RPSEnum.ROCK},
			   {RPSEnum.PAPER,RPSEnum.SCISSORS}
	 };
	}
	
	
	
	@Test(dataProvider = "testWIN")
	public void testWinPlay(RPSEnum p1, RPSEnum p2){		
		Result tmp=rps.play(p1,p2);
		
		assert (tmp==Result.WIN);
		
	}
	@Test(dataProvider = "testTIE")
	void testTiePlay(RPSEnum p1, RPSEnum p2){
		Result tmp=rps.play(p1,p2);
		
		assert (tmp==Result.TIE);
	}
	
	@Test(dataProvider = "testLOST")
	void testLostPlay(RPSEnum p1, RPSEnum p2){
	Result tmp=rps.play(p1,p2);
	
	assert (tmp==Result.LOST);
	}

}
